<?php

class Path extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Path':
	 * @var integer $id
	 * @var string $loading_place
	 * @var string $pod_place
	 * @var integer $mileage
	 * @var double $perform_pay
	 * @var integer $state
	 * @var string $create_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'path';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('loading_place','length', 'min'=>2,'max'=>100),
			array('pod_place','length','min'=>2,'max'=>100),
			array('loading_place,pod_place,mileage,perform_pay,create_time', 'required'),
			array('mileage, state', 'numerical', 'integerOnly'=>true),
			array('perform_pay', 'numerical'),
			array('perform_pay', 'match' ,'pattern' => '/^\d{1,16}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多16位，小数位2位'),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'loading_place' => '装货地',
			'pod_place' => '卸货地',
			'mileage' => '运输里程(公里)',
			'perform_pay' => '绩效工资(元)',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
}